package com.diandian.pos.dao;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Model;

@Component
public class ActiveRecordConfig {

    // 测试所用jfinal model
    public static class UserModel extends Model<UserModel> {

        private static final long serialVersionUID = 4020770190917603300L;

        public static final UserModel dao = new UserModel();
    }

    // 由于spring中已经注入了DruidDataSource这里直接拿
    @Autowired
    private DataSource dataSource;

    @Bean(initMethod = "start", destroyMethod = "stop")
    public ActiveRecordPlugin init() {
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dataSource);
        arp.setShowSql(true);
        return arp;
    }
}

